<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input id="treeId"  name="deptId" type="hidden"/>
                <input id="categoryTreeId"  name="params[thingId]" type="hidden"/>
                <input id="thingTypeId"  name="thingTypeId" type="hidden"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label>行名称：</label>
                            <input readonly="readonly" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属行" >
                        </li>
                        <li>
                            <label>物品目录：</label>
                            <input readonly="readonly" onclick="selectCategoryTree()" id="categoryTreeName" type="text" placeholder="请选择物品分类" >
                        </li>
                        <li>
                            <label style="width: 100px">物品名称：</label>
                            <input type="text" name="createName"/>
                        </li>
                        <li>
                            <label>物品信息：</label>
                            <input type="text" name="mohu"/>
                        </li>
                        <li>
                            <label>收支项目：</label>
                            <input readonly="readonly" onclick="selectThingTypeTree()" id="thingType" type="text" placeholder="请选择收支项目" >
                        </li>

                        <li>
                            <label>入库人：</label>
                            <input type="text" name="createBy"/>
                        </li>
<!--                        <li>-->
<!--                            <label>入库类型：</label>-->
<!--                            <select name="enterType" th:with="type=${@dict.getType('f_enter_type')}">-->
<!--                                <option value="">所有</option>-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"-->
<!--                                        th:value="${dict.dictValue}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <label>发票号：</label>
                            <input type="text" name="lnvoiceNumber"/>
                        </li>
                        <li class="select-time">
                            <label>入库时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="chongzhi()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="financial:fEnter:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="financial:fEnter:edit">-->
            <!--                    <i class="fa fa-edit"></i> 修改-->
            <!--                </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="financial:fEnter:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="financial:fEnter:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="financial:fEnter:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('financial:fEnter:edit')}]];
    var removeFlag = [[${@permission.hasPermi('financial:fEnter:remove')}]];

    var enterTypeDatas = [[${@dict.getType('f_enter_type')}]];

    var prefix = ctx + "financial/fEnter";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "入库管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'enterId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '行名称'
                },
                {
                    field: 'thingName',
                    title: '物品目录'
                },
                {
                    field: 'thingType',
                    title: '收支项目'
                },
                {
                    field: 'createName',
                    title: '物品名称'
                },
                {
                    field: 'mohu',
                    title: '物品信息',
                },
                {
                    field: 'shuliang',
                    title: '数量'
                },
                {
                    field: 'danjia',
                    title: '单价',
                    formatter: function (value, row, index) {
                        var str = ""
                        if(row.averageDanjia){
                            if(parseFloat(value) > parseFloat(row.averageDanjia)){
                                str = "<span style='color: #ED5565'>"+value+"</span>";
                            }else{
                                str = "<span style='color: #1AB394'>"+value+"</span>";
                            }
                        }else{
                            str = ""+value
                        }
                        return str
                    },
                    sortable: true
                },
                {
                    field: 'averageDanjia',
                    title: '平均单价'
                },
                // {
                //     field: 'enterType',
                //     title: '入库类型',
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(enterTypeDatas, value);
                //     }
                // },
                {
                    field: 'lnvoiceNumber',
                    title: '发票号',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    field: 'createBy',
                    title: '入库人'
                },
                {
                    field: 'enterTime',
                    title: '入库时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    width:130,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.enterId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.enterId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择行',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectCategoryTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/fThing/selectFThingCategoryTree/";
        var options = {
            title: '选择物品',
            width: "380",
            url: url,
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }
    function doSubmit2(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#categoryTreeId").val(body.find('#treeId').val());
        $("#categoryTreeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectThingTypeTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/thingType/selectThingTypeTree/";
        var options = {
            title: '选择收支项目',
            width: "380",
            url: url,
            callBack: doSubmit3
        };
        $.modal.openOptions(options);
    }
    function doSubmit3(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#thingTypeId").val(body.find('#treeId').val());
        $("#thingType").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function chongzhi() {
        $("#treeId").val("")
        $("#categoryTreeId").val("")
        $("#thingType").val("")
        $("#thingTypeId").val("")
        //$(".select2-selection__rendered").html("所有")
        $.form.reset()
    }

</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>